#Boa:FramePanel:PanelSkuSearch

import wx
import wx.lib.buttons
from product import *

[wxID_PANELSKUSEARCH, wxID_PANELSKUSEARCHBTN1_1, wxID_PANELSKUSEARCHBTN1_10, 
 wxID_PANELSKUSEARCHBTN1_11, wxID_PANELSKUSEARCHBTN1_2, 
 wxID_PANELSKUSEARCHBTN1_3, wxID_PANELSKUSEARCHBTN1_4, 
 wxID_PANELSKUSEARCHBTN1_5, wxID_PANELSKUSEARCHBTN1_6, 
 wxID_PANELSKUSEARCHBTN1_7, wxID_PANELSKUSEARCHBTN1_8, 
 wxID_PANELSKUSEARCHBTN1_9, wxID_PANELSKUSEARCHBTN2_1, 
 wxID_PANELSKUSEARCHBTN2_10, wxID_PANELSKUSEARCHBTN2_11, 
 wxID_PANELSKUSEARCHBTN2_2, wxID_PANELSKUSEARCHBTN2_3, 
 wxID_PANELSKUSEARCHBTN2_4, wxID_PANELSKUSEARCHBTN2_5, 
 wxID_PANELSKUSEARCHBTN2_6, wxID_PANELSKUSEARCHBTN2_7, 
 wxID_PANELSKUSEARCHBTN2_8, wxID_PANELSKUSEARCHBTN2_9, 
 wxID_PANELSKUSEARCHBTN3_1, wxID_PANELSKUSEARCHBTN3_10, 
 wxID_PANELSKUSEARCHBTN3_11, wxID_PANELSKUSEARCHBTN3_2, 
 wxID_PANELSKUSEARCHBTN3_3, wxID_PANELSKUSEARCHBTN3_4, 
 wxID_PANELSKUSEARCHBTN3_5, wxID_PANELSKUSEARCHBTN3_6, 
 wxID_PANELSKUSEARCHBTN3_7, wxID_PANELSKUSEARCHBTN3_8, 
 wxID_PANELSKUSEARCHBTN3_9, wxID_PANELSKUSEARCHSTATICTEXT1, 
 wxID_PANELSKUSEARCHSTATICTEXT2, wxID_PANELSKUSEARCHSTATICTEXT3, 
] = [wx.NewId() for _init_ctrls in range(37)]

class PanelSkuSearch(wx.Panel):
    def _init_ctrls(self, prnt):
        # generated method, don't edit
        wx.Panel.__init__(self, id=wxID_PANELSKUSEARCH, name=u'PanelSkuSearch',
              parent=prnt, pos=wx.Point(343, 280), size=wx.Size(770, 146),
              style=wx.TAB_TRAVERSAL)
        self.SetClientSize(wx.Size(754, 107))

        self.staticText1 = wx.StaticText(id=wxID_PANELSKUSEARCHSTATICTEXT1,
              label=u'\u6807\u7b7e1', name='staticText1', parent=self,
              pos=wx.Point(8, 16), size=wx.Size(31, 14), style=0)

        self.staticText2 = wx.StaticText(id=wxID_PANELSKUSEARCHSTATICTEXT2,
              label=u'\u6807\u7b7e2', name='staticText2', parent=self,
              pos=wx.Point(8, 48), size=wx.Size(31, 14), style=0)

        self.staticText3 = wx.StaticText(id=wxID_PANELSKUSEARCHSTATICTEXT3,
              label=u'\u6807\u7b7e3', name='staticText3', parent=self,
              pos=wx.Point(8, 80), size=wx.Size(31, 14), style=0)

        self.btn1_2 = wx.lib.buttons.GenToggleButton(id=wxID_PANELSKUSEARCHBTN1_2,
              label='GenToggleButton1', name=u'btn1_2', parent=self, pos=wx.Point(130,
              8), size=wx.Size(60, 26), style=0)

        self.btn1_5 = wx.lib.buttons.GenToggleButton(id=wxID_PANELSKUSEARCHBTN1_5,
              label='GenToggleButton1', name=u'btn1_5', parent=self, pos=wx.Point(310,
              8), size=wx.Size(60, 26), style=0)

        self.btn1_3 = wx.lib.buttons.GenToggleButton(id=wxID_PANELSKUSEARCHBTN1_3,
              label='GenToggleButton1', name=u'btn1_3', parent=self, pos=wx.Point(190,
              8), size=wx.Size(60, 26), style=0)

        self.btn2_11 = wx.lib.buttons.GenToggleButton(id=wxID_PANELSKUSEARCHBTN2_11,
              label='GenToggleButton1', name=u'btn2_11', parent=self,
              pos=wx.Point(670, 40), size=wx.Size(60, 26), style=0)

        self.btn2_10 = wx.lib.buttons.GenToggleButton(id=wxID_PANELSKUSEARCHBTN2_10,
              label='GenToggleButton1', name=u'btn2_10', parent=self,
              pos=wx.Point(610, 40), size=wx.Size(60, 26), style=0)

        self.btn2_9 = wx.lib.buttons.GenToggleButton(id=wxID_PANELSKUSEARCHBTN2_9,
              label='GenToggleButton1', name=u'btn2_9', parent=self, pos=wx.Point(550,
              40), size=wx.Size(60, 26), style=0)

        self.btn1_1 = wx.lib.buttons.GenToggleButton(id=wxID_PANELSKUSEARCHBTN1_1,
              label='genToggleButton1', name=u'btn1_1', parent=self,
              pos=wx.Point(70, 8), size=wx.Size(60, 26), style=0)

        self.btn2_4 = wx.lib.buttons.GenToggleButton(id=wxID_PANELSKUSEARCHBTN2_4,
              label='GenToggleButton1', name=u'btn2_4', parent=self, pos=wx.Point(250,
              40), size=wx.Size(60, 26), style=0)

        self.btn2_6 = wx.lib.buttons.GenToggleButton(id=wxID_PANELSKUSEARCHBTN2_6,
              label='GenToggleButton1', name=u'btn2_6', parent=self, pos=wx.Point(370,
              40), size=wx.Size(60, 26), style=0)

        self.btn2_7 = wx.lib.buttons.GenToggleButton(id=wxID_PANELSKUSEARCHBTN2_7,
              label='GenToggleButton1', name=u'btn2_7', parent=self, pos=wx.Point(430,
              40), size=wx.Size(60, 26), style=0)

        self.btn2_8 = wx.lib.buttons.GenToggleButton(id=wxID_PANELSKUSEARCHBTN2_8,
              label='GenToggleButton1', name=u'btn2_8', parent=self, pos=wx.Point(490,
              40), size=wx.Size(60, 26), style=0)

        self.btn2_1 = wx.lib.buttons.GenToggleButton(id=wxID_PANELSKUSEARCHBTN2_1,
              label='genToggleButton1', name=u'btn2_1', parent=self,
              pos=wx.Point(70, 40), size=wx.Size(60, 26), style=0)

        self.btn1_11 = wx.lib.buttons.GenToggleButton(id=wxID_PANELSKUSEARCHBTN1_11,
              label='GenToggleButton1', name=u'btn1_11', parent=self,
              pos=wx.Point(670, 8), size=wx.Size(60, 26), style=0)

        self.btn1_10 = wx.lib.buttons.GenToggleButton(id=wxID_PANELSKUSEARCHBTN1_10,
              label='GenToggleButton1', name=u'btn1_10', parent=self,
              pos=wx.Point(610, 8), size=wx.Size(60, 26), style=0)

        self.btn1_9 = wx.lib.buttons.GenToggleButton(id=wxID_PANELSKUSEARCHBTN1_9,
              label='GenToggleButton1', name=u'btn1_9', parent=self, pos=wx.Point(550,
              8), size=wx.Size(60, 26), style=0)

        self.btn1_8 = wx.lib.buttons.GenToggleButton(id=wxID_PANELSKUSEARCHBTN1_8,
              label='GenToggleButton1', name=u'btn1_8', parent=self, pos=wx.Point(490,
              8), size=wx.Size(60, 26), style=0)

        self.btn1_7 = wx.lib.buttons.GenToggleButton(id=wxID_PANELSKUSEARCHBTN1_7,
              label='GenToggleButton1', name=u'btn1_7', parent=self, pos=wx.Point(430,
              8), size=wx.Size(60, 26), style=0)

        self.btn1_6 = wx.lib.buttons.GenToggleButton(id=wxID_PANELSKUSEARCHBTN1_6,
              label='GenToggleButton1', name=u'btn1_6', parent=self, pos=wx.Point(370,
              8), size=wx.Size(60, 26), style=0)

        self.btn2_5 = wx.lib.buttons.GenToggleButton(id=wxID_PANELSKUSEARCHBTN2_5,
              label='GenToggleButton1', name=u'btn2_5', parent=self, pos=wx.Point(310,
              40), size=wx.Size(60, 26), style=0)

        self.btn1_4 = wx.lib.buttons.GenToggleButton(id=wxID_PANELSKUSEARCHBTN1_4,
              label='GenToggleButton1', name=u'btn1_4', parent=self, pos=wx.Point(250,
              8), size=wx.Size(60, 26), style=0)

        self.btn2_3 = wx.lib.buttons.GenToggleButton(id=wxID_PANELSKUSEARCHBTN2_3,
              label='GenToggleButton1', name=u'btn2_3', parent=self, pos=wx.Point(190,
              40), size=wx.Size(60, 26), style=0)

        self.btn2_2 = wx.lib.buttons.GenToggleButton(id=wxID_PANELSKUSEARCHBTN2_2,
              label='GenToggleButton1', name=u'btn2_2', parent=self, pos=wx.Point(130,
              40), size=wx.Size(60, 26), style=0)

        self.btn3_1 = wx.lib.buttons.GenToggleButton(id=wxID_PANELSKUSEARCHBTN3_1,
              label='genToggleButton1', name=u'btn3_1', parent=self,
              pos=wx.Point(70, 72), size=wx.Size(60, 26), style=0)

        self.btn3_11 = wx.lib.buttons.GenToggleButton(id=wxID_PANELSKUSEARCHBTN3_11,
              label='GenToggleButton1', name=u'btn3_11', parent=self,
              pos=wx.Point(670, 72), size=wx.Size(60, 26), style=0)

        self.btn3_10 = wx.lib.buttons.GenToggleButton(id=wxID_PANELSKUSEARCHBTN3_10,
              label='GenToggleButton1', name=u'btn3_10', parent=self,
              pos=wx.Point(610, 72), size=wx.Size(60, 26), style=0)

        self.btn3_9 = wx.lib.buttons.GenToggleButton(id=wxID_PANELSKUSEARCHBTN3_9,
              label='GenToggleButton1', name=u'btn3_9', parent=self, pos=wx.Point(550,
              72), size=wx.Size(60, 26), style=0)

        self.btn3_8 = wx.lib.buttons.GenToggleButton(id=wxID_PANELSKUSEARCHBTN3_8,
              label='GenToggleButton1', name=u'btn3_8', parent=self, pos=wx.Point(490,
              72), size=wx.Size(60, 26), style=0)

        self.btn3_7 = wx.lib.buttons.GenToggleButton(id=wxID_PANELSKUSEARCHBTN3_7,
              label='GenToggleButton1', name=u'btn3_7', parent=self, pos=wx.Point(430,
              72), size=wx.Size(60, 26), style=0)

        self.btn3_6 = wx.lib.buttons.GenToggleButton(id=wxID_PANELSKUSEARCHBTN3_6,
              label='GenToggleButton1', name=u'btn3_6', parent=self, pos=wx.Point(370,
              72), size=wx.Size(60, 26), style=0)

        self.btn3_5 = wx.lib.buttons.GenToggleButton(id=wxID_PANELSKUSEARCHBTN3_5,
              label='GenToggleButton1', name=u'btn3_5', parent=self, pos=wx.Point(310,
              72), size=wx.Size(60, 26), style=0)

        self.btn3_4 = wx.lib.buttons.GenToggleButton(id=wxID_PANELSKUSEARCHBTN3_4,
              label='GenToggleButton1', name=u'btn3_4', parent=self, pos=wx.Point(250,
              72), size=wx.Size(60, 26), style=0)

        self.btn3_3 = wx.lib.buttons.GenToggleButton(id=wxID_PANELSKUSEARCHBTN3_3,
              label='GenToggleButton1', name=u'btn3_3', parent=self, pos=wx.Point(190,
              72), size=wx.Size(60, 26), style=0)

        self.btn3_2 = wx.lib.buttons.GenToggleButton(id=wxID_PANELSKUSEARCHBTN3_2,
              label='GenToggleButton1', name=u'btn3_2', parent=self, pos=wx.Point(130,
              72), size=wx.Size(60, 26), style=0)

    def __init__(self, parent, notify_window):
        self._init_ctrls(parent)
        
        self.notify_window = notify_window
        for i in range(1,4):
            for j in range(1,12):
                self.__dict__["btn"+str(i)+"_"+str(j)].Show(False)
                self.__dict__["btn"+str(i)+"_"+str(j)].Bind(wx.EVT_BUTTON, self.OnBtnClicked)
                #self.__dict__["btn"+str(i)+"_"+str(j)].Bind(wx.EVT_TOGGLEBUTTON, self.OnBtnToggleClicked)
        
        self.style_off = """
            ToggleButton{
                  background-color:grey;
            }
        """
      
        self.style_on = """
            ToggleButton{
                  background-color:green;
            }
        """

    def set_category(self, categoryId):
        

        for i in range(1,4):
            self.__dict__["staticText"+str(i)].Show(False)
            for j in range(1,12):
                self.__dict__["btn"+str(i)+"_"+str(j)].Show(False)
                self.__dict__["btn"+str(i)+"_"+str(j)].SetValue(False)
                self.__dict__["btn"+str(i)+"_"+str(j)].SetBackgroundColour("white")#SetWindowStyle(self.style_off)
        
        self.m_group = []
        self.m_sku = []   
        i = 0   
        for group_id,group_name,sku in CDataCategory.get_sku(categoryId):
            i += 1
            j = 0 
            self.__dict__["staticText"+str(i)].Show(True)
            self.__dict__["staticText"+str(i)].SetLabel(group_name)
            self.m_group.append(group_id)
            self.m_sku.append([])
            for s in sku.split(';;'):
                self.m_sku[i-1].append(s.split('::'))
            
            for sku_id,sku_name in self.m_sku[i-1]:
                j += 1
                self.__dict__["btn"+str(i)+"_"+str(j)].Show(True)
                self.__dict__["btn"+str(i)+"_"+str(j)].SetLabel(sku_name)
                

    def get_sku(self):
        '''
        return [(selected_goup_id,[selected_goup_id,]),((),)]
        '''
        import itertools
        
        group_id=[]
        sku_id = [[],[],[]]
        for i in range(1,4):
            for j in range(1,12):
                if(self.__dict__["btn"+str(i)+"_"+str(j)].GetValue()):
                    if self.m_group[i-1] not in group_id:
                        group_id.append(self.m_group[i-1])
                    sku_id[i-1].append(self.m_sku[i-1][j-1][0])
                    
        print self.m_sku
        print sku_id
        
        for i in (2,1,0):
            if len(sku_id[i]) == 0:
                del sku_id[i]
            
        if len(sku_id) == 1:
            #return (group_id,(sku_id[0],))
            return (group_id,tuple(itertools.product(sku_id[0])))
        elif len(sku_id) == 2:    
            return (group_id,tuple(itertools.product(sku_id[0],sku_id[1])))
        elif len(sku_id) == 3:    
            return (group_id,tuple(itertools.product(sku_id[0],sku_id[1],sku_id[2])))
        else:
            return ((),())
            
       
    def OnBtnClicked(self, event):
        btn = event.GetEventObject()
        if btn.GetValue():
            btn.SetBackgroundColour("green")
        else:
            btn.SetBackgroundColour("white")
        self.notify_window.ChangeSkuSearch(self.get_sku())        

    
    def set_sku(self, pro_id):
        
        for group_id,sku_id in CDataProduct.get_sku(pro_id):
            i = self.m_group.index(group_id)
            for j in range(len(self.m_sku[i])):
                if self.m_sku[i][j][0] == sku_id:
                    self.__dict__["btn"+str(i+1)+"_"+str(j+1)].SetValue(True)
                    self.__dict__["btn"+str(i)+"_"+str(j)].SetBackgroundColour("green")#.SetWindowStyle(self.style_on)
                    break
        
        
